﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Barbar.UrlGuard.Controls;
using Barbar.UrlGuard.Dal;

namespace Barbar.UrlGuard {
  public partial class FormAddOrEditChainDialog : LocalizableForm, IInjector<MonitoringChain>, ILocalizable {
    private string m_TitleEditing;
    private string m_TitleCreating;
    private bool m_EditingMode = false;

    private void SetTitle() {
      if (m_EditingMode)
        Text = m_TitleEditing;
      else
        Text = m_TitleCreating;
    }

    public FormAddOrEditChainDialog() {
      InitializeComponent();
    }

    #region IInjector<MonitoringChain> Members

    public void SaveData(MonitoringChain instance) {
      if (instance == null)
        throw new ArgumentNullException("instance");

      instance.Name = txtChainName.Text;
    }

    #endregion

    #region IReadOnlyInjector<MonitoringChain> Members

    public void LoadData(MonitoringChain readOnlyInstance) {
      if (readOnlyInstance == null) {
        txtChainName.Text = string.Empty;
        m_EditingMode = false;
      } else {
        txtChainName.Text = readOnlyInstance.Name;
        m_EditingMode = true;
      }
      SetTitle();
    }

    #endregion

    #region ILocalizable Members

    public void Localize(ILocalizator localizator) {
      if (localizator == null)
        throw new ArgumentNullException("localizator");

      m_TitleCreating = localizator.Translate("FormAddOrEditChainDialog_TitleCreate");
      m_TitleEditing = localizator.Translate("FormAddOrEditChainDialog_TitleEdit");
      SetTitle();
    }

    #endregion
  }
}
